package HuaweiOD;

import java.util.Scanner;

public class We_Are_A_Team {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int m = in.nextInt();

        int[][] msgs = new int[m][3];
        for (int i = 0; i < m; i++) {
            msgs[i][0] = in.nextInt();
            msgs[i][1] = in.nextInt();
            msgs[i][2] = in.nextInt();
        }

        solve(msgs, n, m);
    }

    public static void solve(int[][] msgs, int n, int m) {
        if (n < 1 || n >= 100000 || m < 1 || m >= 100000) {
            System.out.println("NULL");
            return;
        }

        UnionFind unionFind = new UnionFind(n + 1);
        for (int[] msg : msgs) {
            int a = msg[0], b = msg[1], c = msg[2];
            if (a < 1 || a > n || b < 1 || b > n) {
                System.out.println("da pian zi");
                continue;
            }

            if (c == 0) {
                unionFind.union(a, b);
            }else if (c == 1){
                System.out.println(unionFind.find(a) == unionFind.find(b) ? "we are a team" : "we are not a team");
            }else {
                System.out.println("da pian zi");
            }
        }
    }
}

class UnionFind {
    int[] fa;

    public UnionFind(int n) {
        fa = new int[n];
        for (int i = 0; i < n; i++) {
            fa[i] = i;
        }
    }

    public int find(int x) {
        if (fa[x] != x) {
            return fa[x] = find(fa[x]);
        }
        return x;
    }

    public void union(int x, int y) {
        int x_fa = find(x);
        int y_fa = find(y);

        if (x_fa != y_fa) {
            fa[x_fa] = y_fa;
        }
    }
}